#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>

void preprocess_p(char* p) 
{
    int len = strlen(p);
    int j = 0;
    for (int i = 0; i < len; i++)
    {
        if (p[i] == '*')
        {
            if (j > 0 && p[j - 1] == '*') 
            {
                continue;
            }
            else 
            {
                p[j++] = '*';
            }
        }
        else 
        {
            p[j++] = p[i];
        }
    }
    p[j] = '\0';
}

int main()
{
    char p[10001];
    char s[10001];
    fgets(p, sizeof(p), stdin);
    fgets(s, sizeof(s), stdin);
    p[strcspn(p, "\n")] = 0;
    s[strcspn(s, "\n")] = 0;

    preprocess_p(p);
    int plen = strlen(p);
    int slen = strlen(s);

    if (plen == 0)
    {
        for (int i = 0; i <= slen; i++) 
        {
            for (int L = 0; L <= slen - i; L++)
            {
                printf("%d %d\n", i, L);
            }
        }
        return 0;
    }

    int capacity = 10000;
    int* starts = (int*)malloc(capacity * sizeof(int));
    int* lengths = (int*)malloc(capacity * sizeof(int));
    int count = 0;

    for (int i = 0; i <= slen; i++) 
    {
        int maxL = slen - i;
        if (p[0] != '*')
        {
            if (maxL < 1) continue;
            if (s[i] != p[0]) continue;
        }
        for (int L = 0; L <= maxL; L++) 
        {
            if (L == 0) continue;
            if (p[plen - 1] != '*') 
            {
                if (s[i + L - 1] != p[plen - 1]) 
                {
                    continue;
                }
            }

            bool* dp0 = (bool*)calloc(L + 1, sizeof(bool));
            bool* dp1 = (bool*)calloc(L + 1, sizeof(bool));
            dp0[0] = true;

            for (int j = 1; j <= plen; j++)
            {
                for (int k = 0; k <= L; k++)
                {
                    if (p[j - 1] == '*') 
                    {
                        dp1[k] = dp0[k] || (k > 0 && dp1[k - 1]);
                    }
                    else 
                    {
                        dp1[k] = (k > 0) && (s[i + k - 1] == p[j - 1]) && dp0[k - 1];
                    }
                }
                bool* temp = dp0;
                dp0 = dp1;
                dp1 = temp;
            }

            if (dp0[L]) 
            {
                if (count >= capacity) 
                {
                    capacity *= 2;
                    starts = (int*)realloc(starts, capacity * sizeof(int));
                    lengths = (int*)realloc(lengths, capacity * sizeof(int));
                }
                starts[count] = i;
                lengths[count] = L;
                count++;
            }

            free(dp0);
            free(dp1);
        }
    }

    if (count == 0)
    {
        printf("-1 0\n");
    }
    else
    {
        for (int i = 0; i < count; i++) 
        {
            printf("%d %d\n", starts[i], lengths[i]);
        }
    }

    free(starts);
    free(lengths);
    return 0;
}